/*
 * main.cpp
 *
 *  Created on: 03/06/2011
 *      Author: dela
 */

#include <string>
#include <iostream>
#include <stdlib.h>
#include <gtkmm.h>
#include "common/view/Login.h"
#include "common/Connection.h"
#include "common/Course.h"
#include "common/Class.h"

using namespace std;


/**
 *
 */
void testLogin() {
	bool login = false;
	string user;
	string password;
	while (!login) {
		cout << "Usuario: ";
		cin >> user;
		cout << "Constraseña: ";
		cin >> password;
		login = Connection::getInstance()->login( user, password );
	}
}

/**
 *
 */
void testCreateCourse() {
	Course c = Course();
	c.setId(8);
	c.setName("Mi Nombre");
	c.setDescription("Una descripcion");
	c.setHasPassword(true);
	c.setPassword("La password");
	c.setStartDate("30/6/2011");
	c.setDuration("2h");

	cout << "Resultado de creación: " << Connection::getInstance()->createCourse(c) << endl;
}


/**
 *
 */
void testCreateClass() {
	Class c = Class();
	c.setId(444);
	c.setName("Mi Clase");
	c.setDescription("Una desc de clase");
	c.setHasPassword(true);
	c.setPassword("Lalala");
	c.setStartDate("8/8/2011");
	c.setDuration("4h");

	cout << "Resultado de creación: " << Connection::getInstance()->createClass(c) << endl;
}


Connection *Connection::conn = NULL;

/**
 *
 */
int main(int argc, char *argv[]) {
	// Si es incorrecta la cantidad de parametros salgo:
	if ( argc != 3 ) {
		cout << "Parametros esperados: ip y puerto." << endl;
		return -1;
	}
	int iport = atoi(argv[2]);

	Connection::createSingleton(argv[1], iport);
	Connection::getInstance()->initConnection();
	Connection::getInstance()->setType('I');


	// TEST DE LOGIN: TODO
	//testLogin();

	// TEST CREACION DE CURSO: TODO
	//testCreateCourse();
	//testCreateClass();

	// GTK:
	Gtk::Main kit(argc, argv);

	Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("glade/instructor/login.glade");

	Login* login = 0;
	builder->get_widget_derived("window1", login);
	kit.run( *login );

	cout << "Desconectando..." << endl;
}

